<template>
	<view class="conter">
		<u-popup bgColor="#1c213a" round="18" :show="show" mode="center" closeOnClickOverla="false">
			<view class="popup">
				<image src="../../static/images/renzheng.png" mode=""></image>
				<u-icon @click="closeDialog" class="icon" name="close" color="#fff" bold size="20"></u-icon>
				<view class="name">实名认证</view>
				<u--input v-model="name" input-align="center" placeholder="点击输入真实的姓名" class="input" border="none"></u--input>
				<u--input v-model="phone" class="input" maxlength="11" placeholder="点击输入真实手机号" border="none" input-align="center"></u--input>
				<u--input v-model="idNumber" class="input" maxlength="18" placeholder="点击输入身份证号码" border="none" input-align="center"></u--input>
				<view @click="confim" class="button">确认</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
import { realName } from '@/api/account/account.js';
import { toast } from '@/utils/common';
import config from '@/config.js';
import { getInfo } from '@/api/login.js';
import { getToken, getUserAdmin, setUserAdmin } from '@/utils/auth';
import { filterPhone, filterName, filterIdNumber } from '@/utils/filter.js';
export default {
	props: {
		dialogValue: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			show: true,
			imgUrl: config.imgUrl,
			userId: '',
			name: '',
			phone: '',
			idNumber: ''
		};
	},
	created() {
		let userDetail = getUserAdmin();
		if (userDetail.isRealName == 1) {
			this.filter(userDetail);
		}
	},
	onLoad(option) {
		if (option.userId) {
			this.userId = option.userId;
		}
	},
	methods: {
		closeDialog() {
			// 向父组件发送关闭弹框的信号
			this.$emit('closeDialog');
		},
		// 过滤信息
		filter(userDetail) {
			this.name = filterName(userDetail.name);
			this.phone = filterPhone(userDetail.phone);
			this.idNumber = filterIdNumber(userDetail.idNumber);
			this.show = false;
		},
		async confim() {
			if (!this.name) {
				toast('姓名不能为空');
			}
			if (!this.phone) {
				toast('手机号不能为空');
			}
			if (!this.idNumber) {
				toast('身份证号不能为空');
			}
			let param = {};
			param.name = this.name;
			param.phone = this.phone;
			param.idNumber = this.idNumber;
			const res = await realName(param);
			if (res.code == 200) {
				toast('实名成功');
			}
			const info = await getInfo();
			console.log(info);
			uni.setStorageSync('USER_ADMIN', info.data);
			this.filter(info.data);
			this.show = false;
			this.name = '';
			this.phone = '';
			this.idNumber = '';
		},
		guan() {
			this.show = false;
		}
	}
};
</script>

<style scoped lang="less">
::v-deep .uni-input-input {
	color: #ffffff;
	margin-top: 5rpx;
}

::v-deep .input-placeholder {
	font-size: 24rpx;
	font-family: Source Han Sans, Source Han Sans;
	font-weight: 200;
	color: #8a92a3 !important;
	margin-top: 5rpx;
	margin-left: -80rpx;
}

.popup {
	margin: auto;
	width: 491rpx;
	height: 590rpx;
	padding: 61rpx 34.88rpx;
	background: #232946;
	border-radius: 18rpx;
	position: relative;
	box-shadow: 0rpx 4rpx 11rpx 0rpx rgba(0, 0, 0, 0.3);

	image {
		width: 170rpx;
		height: 170rpx;
		top: -110rpx;
		left: 165rpx;
		position: absolute;
	}

	.icon {
		right: 34.88rpx;
		top: 34.88rpx;
		position: absolute;
	}

	.name {
		color: #ffffff;
		font-weight: 700;
		font-size: 30rpx;
		font-family: 'font';
		text-align: center;
	}

	.input {
		width: 420rpx;
		height: 77rpx;
		background: #211f30;
		margin-top: 33rpx;
		border-radius: 44rpx;
		border: 1rpx solid #3c424d;
	}

	.button {
		width: 420rpx;
		height: 77rpx;
		font-weight: 500;
		color: #ffffff;
		font-size: 28rpx;
		margin-top: 53rpx;
		text-align: center;
		line-height: 82rpx;
		border-radius: 44rpx;
		background: linear-gradient(90deg, #3adfeb 0%, #4463ff 100%);
	}
}
</style>
